package com.me.study.ui.activity.blue

import android.Manifest
import android.os.Bundle
import com.me.study.R
import com.me.study.app.base.BaseActivity
import com.me.study.app.laserRange.ACSUtility
import com.me.study.databinding.ActivityLaserRangeBinding
import com.permissionx.guolindev.PermissionX
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel

class LaserRangeActivity : BaseActivity<BaseViewModel, ActivityLaserRangeBinding>() {

    private lateinit var acsUtility: ACSUtility

    override fun layoutId() = R.layout.activity_laser_range

    override fun initView(savedInstanceState: Bundle?) {

    }

    override fun onResume() {
        super.onResume()
        PermissionX.init(this)
            .permissions(
                Manifest.permission.BLUETOOTH_SCAN,
                Manifest.permission.BLUETOOTH_CONNECT,
                Manifest.permission.BLUETOOTH_ADMIN,
                Manifest.permission.BLUETOOTH,
                Manifest.permission.ACCESS_FINE_LOCATION
            )
            .request { allGranted, grantedList, deniedList ->
                if (allGranted) {
                    acsUtility = ACSUtility(this, ACSCallback())
                } else {

                }
            }
    }

    inner class ACSCallback : ACSUtility.IACSUtilityCallback {

        override fun utilReadyForUse() {
            acsUtility.enumAllPorts(10f)
        }

        override fun didFoundPort(newPort: ACSUtility.blePort?) {
            runOnUiThread {
                newPort?.let {
                    it._device

                }
            }
        }

        override fun didFinishedEnumPorts() {

        }

        override fun didOpenPort(port: ACSUtility.blePort?, bSuccess: Boolean?) {

        }

        override fun didClosePort(port: ACSUtility.blePort?) {

        }

        override fun didPackageSended(succeed: Boolean) {

        }

        override fun didPackageReceived(port: ACSUtility.blePort?, packageToSend: ByteArray?) {

        }

        override fun heartbeatDebug() {

        }

    }
}